﻿Imports System.Text.RegularExpressions

Module PatternEx
    Function ExtractPattern(ByVal Data As String) As String
        Dim i As Long, Pattern As String = ""
        For i = 1 To Len(Data)
            Pattern = Pattern & Get_Type(Mid(Data, i, 1))
        Next
    End Function

    Function UpdatePattern(ByVal Data1 As String, ByVal Data2 As String, ByVal Pattern As String) As String
        'Here we assume Data1 Length = Data2 Length
        Dim i As Long, C1 As String, C2 As String
        If Len(Data2) < Len(Data1) Then Return 0
        For i = 1 To Len(Data1)
            C1 = Mid(Data1, i, 1)
            C2 = Mid(Data2, i, 1)
            If C1 = C2 Then
                Pattern = Pattern & C1
            ElseIf IsUString(C1) And IsUString(C2) Then
                Pattern = Pattern & "[A-Z]{1}"
            ElseIf (IsUString(C1) And IsLString(C2)) Or (IsUString(C2) And IsLString(C1)) Then
                Pattern = Pattern & "[a-zA-Z]{1}"
            ElseIf IsLString(C1) And IsLString(C2) Then
                Pattern = Pattern & "[a-z]{1}"
            ElseIf IsNumeric(C1) And IsNumeric(C2) Then
                Pattern = Pattern & "[0-9]{1}"
            ElseIf IsNumeric(C1) And IsLString(C2) Then
                Pattern = Pattern & "[0-9a-z]{1}"
            ElseIf IsNumeric(C1) And IsUString(C2) Then
                Pattern = Pattern & "[0-9A-Z]{1}"
            End If
        Next
    End Function
    Function Get_Type(ByVal Data As String) As String
        If IsNumeric(Data) Then Return "[0-9]|\.{" & Len(Data) & "}"
        If Regex.Match(Data, "\w").Success Then Return "[a-z]{" & Len(Data) & "}"
        If Regex.Match(Data, "\W").Success Then Return "[A-Z]{" & Len(Data) & "}"
        Return "[^a-zA-Z0-9]{" & Len(Data) & "}"
    End Function
    Function IsUString(ByVal Data As String) As Boolean

    End Function
    Function IsLString(ByVal Data As String) As Boolean

    End Function

End Module
